const fs = require('fs');
const path = require('path');
import dotenv from "dotenv";
// @ts-ignore
import dayjs from "dayjs";

export const getCurrentTime = () => dayjs().format("YYYY-MM-DD HH:mm:ss");

dotenv.config(); //使用环境变量
export const getEnv1 = () => process?.env.NODE_ENV?.trim() || "production";

export const isDevelopment = () => getEnv1() === "development";

export const getEnv  = () => process?.env 
export function logger(arg:any,title='') {
    if(isDevelopment()){
        console.log(title+':',arg)
    }else {
        const writeStream = fs.createWriteStream(path.join(__dirname, 'app.log'), { flags: 'a' });
        writeStream.write(getCurrentTime() +'::' + title+':'+JSON.stringify(arg) + '\n');
        writeStream.end();
    }
}